package org.looom.orglooomschool;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.TextView;
public class MyCustomReceiver14 extends BroadcastReceiver {
    private static final String TAG = "MyCustomReceiver";
    private TextView statusTextView;
    //在构造函数中获取活动中的textview
    public MyCustomReceiver14(TextView textView) {
        statusTextView = textView;
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        // 添加日志，确认是否接收到广播
        Log.d(TAG, "Received broadcast: " + intent.getAction());

        // 定义我们自定义的 Action 字符串
        String CUSTOM_SMS_RECEIVED_ACTION = "com.example.myapplication.ACTION_NEW_SMS_RECEIVED";
        // 检查接收到的广播 Action 是否是我们的自定义 Action
        if (CUSTOM_SMS_RECEIVED_ACTION.equals(intent.getAction())) {
            // 更新 TextView
            if (statusTextView != null) {
                statusTextView.setText("收到新的短信息了。 (通过自定义广播)");
                Log.d(TAG, "TextView updated.");
            } else {
                Log.e(TAG, "TextView is null, cannot update UI.");
            }
        }
    }
}
